#ifndef LIGHTHANDLER_H
#define LIGHTHANDLER_H
#include "Lightenums.h"
#include <osgGA/GUIEventHandler>
#include <osg/Camera>
#include <osg/Vec3d>
#include "Clip.h"
#include "LightManager.h"
#include "Hud.h"

class LightHandler : public osgGA::GUIEventHandler 
{
public:
	OpenThreads::Mutex * getLockMutex();

	LightHandler(LightManager* lightManager, HUD * hud);
	~LightHandler();
	bool handle(const osgGA::GUIEventAdapter &ea, 
		osgGA::GUIActionAdapter &aa);

	enum KEYSTATUSTYPE{
		KEY_UP, KEY_DOWN
	};

	struct keyMap{
		keyMap() {keyState = KEY_UP;}
		LIGHTSWITCHES keyAction ;
		KEYSTATUSTYPE keyState;
		BUTTONTYPE btnType;
		SWITCHSTATUS swStatus;
	};
	
	void softSwitch(const int lightNumber);
	void softSwitchRandom(const int lightNumber);
	void createDefaultLightning();
	void createLights();
	void removeLights();
	void toggleCouchSpot(const osg::Vec4d color);
	void discoOrbSpot(const bool on, const osg::Vec4d color);
	void strobo(const bool on);
	void createSpot(const LIGHTNUMBER number, const osg::Vec4d position,
			const osg::Vec4d color, const osg::Vec3d direction, const float spotCutoff);

private:	
    LightManager* _lightManager;
	osg::Light* light;
	osg::Vec3d spotDir;
	osg::Vec4d spotPos;
	HUD * _hud;
	int azimut, pol;
	bool newKeyDownEvent, newKeyUpEvent, couchSpotOn;
	LIGHTSWITCHES m;
	double currentRS, currentGS, currentBS;
	double currentRR, currentGR, currentBR;

	void keyToHandle(int k, LIGHTSWITCHES a, BUTTONTYPE t);

	// Deklariert eine Map zum Speichern der 
	// Keyboardtasten und den dazugehoerigen Funktionen
	typedef std::map<int, keyMap> keyFunctionMap;

	// Eine Map fuer die Key-DOWN Funktionen
	keyFunctionMap keyFuncMap;

	// Eine Map fuer die Key-UP Funktionen
	keyFunctionMap keyUPFuncMap;

	keyFunctionMap::iterator itr;
};

#endif
